package com.sdy.healthcode.h5.task;

import com.sdy.common.utils.DateUtil;
import com.sdy.healthcode.biz.model.ExpertsAppointment;
import com.sdy.healthcode.biz.service.ExpertsAppointmentService;
import com.sdy.mvc.annotation.TaskSync;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
@Slf4j
public class AppointmentExpireTask {
    @Autowired
    private ExpertsAppointmentService expertsAppointmentService;

    @Scheduled(cron = "20 0 0 * * ?")
//    @Scheduled(cron = "0/10 * * * * ?")
    @TaskSync
    public void expire() {
        log.info("开始预约清理工作...");
        Date dateBegin = DateUtil.getDateBegin(new Date());
        expertsAppointmentService.lambdaUpdate()
                .eq(ExpertsAppointment::getState, 1)
                .lt(ExpertsAppointment::getAppointmentDate, dateBegin)
                .set(ExpertsAppointment::getState, 3)
                .update();
        log.info("预约清理工作结束。");
    }
}
